package blog.spring.db.service.impl;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import blog.core.exception.FormParamErrorException;
import blog.core.exception.NotFoundException;
import blog.spring.db.dao.IArticleDAO;
import blog.spring.db.dao.IGlobalDAO;
import blog.spring.db.entity.Global;
import blog.spring.db.service.IGlobalService;

@Service("globalService")
public class GlobalService extends BaseService<Global> implements
		IGlobalService {

	private final IGlobalDAO globalDao;
	public static final String TYPE_NAME = "站点";

	@Resource
	private IArticleDAO articleDao;

	@Autowired
	public GlobalService(IGlobalDAO globalDao) throws FormParamErrorException {
		super(globalDao, TYPE_NAME);
		this.globalDao = globalDao;
		try {
			findById(1);
		} catch (NotFoundException e) {
			save(new Global(1, 0, new Date(), "ACNA 技术博客 | ACNA.CC"));
		}
	}

	@Override
	public void updateArticleCount() {
		findById(1).setArticlesCount(articleDao.selectAllCount());
	}

	private class NewThread implements Runnable {

		@Override
		public void run() {
		}

	}

}
